package day03;

import org.junit.Test;
import pojo.Account;

import java.sql.*;
import java.util.ArrayList;

/**
 * @author Xiao
 * @date 2021/8/20
 */
public class UserLogin02 {
    /**
     * 查询account账户表数据，封装为Account对象中，并且存储到ArrayList集合中。
     */
    public static void main(String[] args) throws Exception{
        String url = "jdbc:mysql:///day03?useSSL=false";
        String username = "root";   // 数据库用户名
        String password = "1234";   // 数据库密码
        Connection conn = DriverManager.getConnection
                (url, username, password);  // 获取连接
        String uname = "zhangsan";
        String pword = "123";
        String sql = "select * from user where username= ? and password = ?";
        PreparedStatement pstm = conn.prepareStatement(sql);
        pstm.setString(1, uname);
        pstm.setString(2, pword);
        ResultSet rs = pstm.executeQuery();
        if (rs.next()) {
            System.out.println("登陆成功。。。");
        } else {
            System.out.println("登录失败。。。");
        }
        pstm.close();
        conn.close();
    }
    @Test
    public static void method() {

    }
}
